<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Promise.allSettled</title>
  </head>
  <body>
    <script>
      // 声明两个promise对象
      const p1 = new Promise(resolve => {
        setTimeout(() => {
          resolve("成功-1");
        }, 1000);
      });

      const p2 = new Promise((resolve, reject) => {
        setTimeout(() => {
          //   resolve("成功-2");
          reject("失败了");
        }, 2000);
      });

      // Promise.allSettled返回状态都为resolved
      const result = Promise.allSettled([p1, p2]);
      result.then(value => {
        console.log(value);
      });

      // Promise.all返回都为成功或者有一个失败
      const res = Promise.all([p1, p2]);
      console.log(res);
    </script>
  </body>
</html>
